<?php

namespace api\libs\swoft;

use api\libs\swoft\core\SwoftCore;
use api\libs\swoft\ifc\SwoftClient;
use yii\helpers\Json;

class SwoftEventrule extends SwoftClient
{
    // 事件规则列表
    public function eventRules($arr_request, $access_token)
    {
        $options[SwoftCore::SWOFT_RESOURCE] = $this->getBaseUri() . 'web/event-rules';
        $options[SwoftCore::SWOFT_QUERY_STRING] = array_merge($arr_request, ['token' => $access_token]);
        $options[SwoftCore::SWOFT_METHOD] = SwoftCore::SWOFT_HTTP_GET;
        return $this->sendRequest($options);
    }
    // 创建事件规则
    public function add($data, $access_token)
    {
        $options[SwoftCore::SWOFT_RESOURCE] = $this->getBaseUri() . 'web/event-rules';
        $options[SwoftCore::SWOFT_QUERY_STRING] = array('token' => $access_token);
        $options[SwoftCore::SWOFT_METHOD] = SwoftCore::SWOFT_HTTP_POST;
        $options[SwoftCore::SWOFT_CONTENT_TYPE] = 'application/json';
        $options[SwoftCore::SWOFT_CONTENT] = Json::encode($data);
        return $this->sendRequest($options);
    }
    // 编辑事件规则
    public function update($id, $data, $access_token) {
        $options[SwoftCore::SWOFT_RESOURCE] = $this->getBaseUri() .  'web/event-rules/' . urldecode($id);
        $options[SwoftCore::SWOFT_QUERY_STRING] = ['token' => $access_token];
        $options[SwoftCore::SWOFT_METHOD] = SwoftCore::SWOFT_HTTP_PUT;
        $options[SwoftCore::SWOFT_CONTENT_TYPE] = 'application/json';
        $options[SwoftCore::SWOFT_CONTENT] = json_encode(['data' => $data]);
        return $this->sendRequest($options);
    }
    // 启用事件规则
    public function start($id, $access_token)
    {
        $options[SwoftCore::SWOFT_RESOURCE] = $this->getBaseUri() . 'web/event-rules/start/' . urldecode($id);
        $options[SwoftCore::SWOFT_QUERY_STRING] = ['token' => $access_token];
        $options[SwoftCore::SWOFT_METHOD] = SwoftCore::SWOFT_HTTP_GET;
        return $this->sendRequest($options);
    }
    // 禁用事件规则
    public function pause($id, $access_token)
    {
        $options[SwoftCore::SWOFT_RESOURCE] = $this->getBaseUri() . 'web/event-rules/pause/' . urldecode($id);
        $options[SwoftCore::SWOFT_QUERY_STRING] = ['token' => $access_token];
        $options[SwoftCore::SWOFT_METHOD] = SwoftCore::SWOFT_HTTP_GET;
        return $this->sendRequest($options);
    }
    // 查看事件规则
    public function getOne($id, $access_token)
    {
        $options[SwoftCore::SWOFT_RESOURCE] = $this->getBaseUri() . 'web/event-rules/' . urldecode($id);
        $options[SwoftCore::SWOFT_QUERY_STRING] = ['token' => $access_token];
        $options[SwoftCore::SWOFT_METHOD] = SwoftCore::SWOFT_HTTP_GET;
        return $this->sendRequest($options);
    }
    // 删除
    public function delete($id, $access_token)
    {
        $options[SwoftCore::SWOFT_RESOURCE] = $this->getBaseUri() . 'web/event-del/' . urldecode($id);
        $options[SwoftCore::SWOFT_QUERY_STRING] = array('token' => $access_token);
        $options[SwoftCore::SWOFT_METHOD] = SwoftCore::SWOFT_HTTP_POST;
        return $this->sendRequest($options);
    }
    // 配置自动立案
    public function caseRule($data, $access_token)
    {
        $options[SwoftCore::SWOFT_RESOURCE] = $this->getBaseUri() . 'web/case-rule';
        $options[SwoftCore::SWOFT_QUERY_STRING] = array('token' => $access_token);
        $options[SwoftCore::SWOFT_METHOD] = SwoftCore::SWOFT_HTTP_POST;
        $options[SwoftCore::SWOFT_CONTENT_TYPE] = 'application/json';
        $options[SwoftCore::SWOFT_CONTENT] = Json::encode($data);
        return $this->sendRequest($options);
    }
    // 配置自动结案
    public function closeRule($data, $access_token)
    {
        $options[SwoftCore::SWOFT_RESOURCE] = $this->getBaseUri() . 'web/close-rule';
        $options[SwoftCore::SWOFT_QUERY_STRING] = array('token' => $access_token);
        $options[SwoftCore::SWOFT_METHOD] = SwoftCore::SWOFT_HTTP_POST;
        $options[SwoftCore::SWOFT_CONTENT_TYPE] = 'application/json';
        $options[SwoftCore::SWOFT_CONTENT] = Json::encode($data);
        return $this->sendRequest($options);
     }
     // 配置自动处置
    public function autoHandle($data, $access_token)
    {
        $options[SwoftCore::SWOFT_RESOURCE] = $this->getBaseUri() . 'web/auto-handle';
        $options[SwoftCore::SWOFT_QUERY_STRING] = array('token' => $access_token);
        $options[SwoftCore::SWOFT_METHOD] = SwoftCore::SWOFT_HTTP_POST;
        $options[SwoftCore::SWOFT_CONTENT_TYPE] = 'application/json';
        $options[SwoftCore::SWOFT_CONTENT] = Json::encode($data);
        return $this->sendRequest($options);
    }
    // 配置自动核查
    public function autoVerify($data, $access_token)
    {
        $options[SwoftCore::SWOFT_RESOURCE] = $this->getBaseUri() . 'web/auto-verify';
        $options[SwoftCore::SWOFT_QUERY_STRING] = array('token' => $access_token);
        $options[SwoftCore::SWOFT_METHOD] = SwoftCore::SWOFT_HTTP_POST;
        $options[SwoftCore::SWOFT_CONTENT_TYPE] = 'application/json';
        $options[SwoftCore::SWOFT_CONTENT] = Json::encode($data);
        return $this->sendRequest($options);
    }
    // 启用
    public function begin($data, $access_token)
    {
        $options[SwoftCore::SWOFT_RESOURCE] = $this->getBaseUri() . 'web/start';
        $options[SwoftCore::SWOFT_QUERY_STRING] = array('token' => $access_token);
        $options[SwoftCore::SWOFT_METHOD] = SwoftCore::SWOFT_HTTP_POST;
        $options[SwoftCore::SWOFT_CONTENT_TYPE] = 'application/json';
        $options[SwoftCore::SWOFT_CONTENT] = Json::encode($data);
        return $this->sendRequest($options);
    }
    // 停用
    public function stop($data, $access_token)
    {
        $options[SwoftCore::SWOFT_RESOURCE] = $this->getBaseUri() . 'web/stop';
        $options[SwoftCore::SWOFT_QUERY_STRING] = array('token' => $access_token);
        $options[SwoftCore::SWOFT_METHOD] = SwoftCore::SWOFT_HTTP_POST;
        $options[SwoftCore::SWOFT_CONTENT_TYPE] = 'application/json';
        $options[SwoftCore::SWOFT_CONTENT] = Json::encode($data);
        return $this->sendRequest($options);
    }
    // 列表
    public function ruleList($arr_request, $access_token)
    {
        $options[SwoftCore::SWOFT_RESOURCE] = $this->getBaseUri() . 'web/rule-list';
        $options[SwoftCore::SWOFT_QUERY_STRING] = array_merge($arr_request, ['token' => $access_token]);
        $options[SwoftCore::SWOFT_METHOD] = SwoftCore::SWOFT_HTTP_GET;
        return $this->sendRequest($options);
    }
    // 删除
    public function eventDel($data, $access_token)
    {
        $options[SwoftCore::SWOFT_RESOURCE] = $this->getBaseUri() . 'web/event-del';
        $options[SwoftCore::SWOFT_QUERY_STRING] = array('token' => $access_token);
        $options[SwoftCore::SWOFT_METHOD] = SwoftCore::SWOFT_HTTP_POST;
        $options[SwoftCore::SWOFT_CONTENT_TYPE] = 'application/json';
        $options[SwoftCore::SWOFT_CONTENT] = Json::encode($data);
        return $this->sendRequest($options);
    }
    // 更改
    public function eventEdit($data, $access_token)
    {
        $options[SwoftCore::SWOFT_RESOURCE] = $this->getBaseUri() . 'web/event-edit';
        $options[SwoftCore::SWOFT_QUERY_STRING] = array('token' => $access_token);
        $options[SwoftCore::SWOFT_METHOD] = SwoftCore::SWOFT_HTTP_POST;
        $options[SwoftCore::SWOFT_CONTENT_TYPE] = 'application/json';
        $options[SwoftCore::SWOFT_CONTENT] = Json::encode($data);
        return $this->sendRequest($options);
    }
    // 规则检查
    public function ruleCheck($arr_request, $access_token)
    {
        $options[SwoftCore::SWOFT_RESOURCE] = $this->getBaseUri() . 'web/rule-check';
        $options[SwoftCore::SWOFT_QUERY_STRING] = array_merge($arr_request, ['token' => $access_token]);
        $options[SwoftCore::SWOFT_METHOD] = SwoftCore::SWOFT_HTTP_GET;
        return $this->sendRequest($options);
    }
}